/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.spring66.training.dao.hibernate;

import com.spring66.training.dao.OwnerDao;
import com.spring66.training.entity.Owner;
import java.util.Collection;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 * @author TwinP
 */
public class OwnerDaoHibernate extends HibernateDaoSupport implements OwnerDao{

    @Override
    public void create(Owner own) {
       getHibernateTemplate().persist(own);
    }

    @Override
    public Owner loadOwner(Integer pk) {
        return (Owner) getHibernateTemplate().load(Owner.class, pk);
    }

    @Override
    public void update(Owner own) {
        getHibernateTemplate().update(own);
    }

    @Override
    public void delete(Owner own) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Owner> readAll() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Collection<Owner> findOwner(String lastName) {
        return getHibernateTemplate().find("from Owner owner where owner.lastName like ?", lastName + "%");
    }

    @Override
    public void storeOwner(Owner own) {
        getHibernateTemplate().saveOrUpdate(own);
    }

}
